<template>
    <el-card>
         <!-- 路径导航 -->
        <div slot="header">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item :to="{ path: '/home' }"> <i class="el-icon-house"></i> 首页</el-breadcrumb-item>
                <el-breadcrumb-item>订单管理</el-breadcrumb-item>
                <el-breadcrumb-item>订单列表</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
         <!-- 主体内容 -->
         <br>
        <!-- 筛选区域 -->
        <div class="filter-bar">
            <!-- 筛选表单 -->
            <div class="l-form">
               <el-form :model="searchForm" label-width="80px" :inline="true" size="small">
                   <el-form-item label="用户ID">
                       <el-input v-model="searchForm.user_id" placeholder="请输入用户ID"></el-input>
                   </el-form-item>
                    <el-form-item label="支付状态">
                       <el-select v-model="searchForm.pay_status"   >
                           <el-option  value="" label="全部状态"> </el-option>
                           <el-option  value="1" label="已付款"> </el-option>
                           <el-option  value="0" label="未付款"> </el-option>
                       </el-select>
                       
                   </el-form-item>
                    <el-form-item label="发货状态">
                        <el-select v-model="searchForm.is_send"   >
                           <el-option  value="" label="全部状态"> </el-option>
                           <el-option  value="是" label="是"> </el-option>
                           <el-option  value="否" label="否"> </el-option>
                       </el-select>
                   </el-form-item>
                   <el-form-item>
                       <el-button type="primary" @click="getOrderList">查询</el-button>
                       <el-button @click="resetSearch">重置</el-button>
                   </el-form-item>
               </el-form>
            </div>
        </div>
         <!-- 表格区域 -->
         <div class="table-box">
             <!-- 表格 -->
             <el-table :data="orderList" border >
                 <el-table-column label="序号" type="index" width="80"></el-table-column>
                 <el-table-column label="订单编号" prop="order_number" width="300"></el-table-column>
                 <el-table-column label="订单价格" prop="order_price"></el-table-column>
                 <el-table-column label="用户ID" prop="user_id"></el-table-column>
                 <el-table-column label="支付状态" >
                     <template slot-scope="scope">
                         <el-tag type="warning" v-if="scope.row.pay_status === '0'" size="normal">未发货</el-tag>
                         <el-tag type="success" v-if="scope.row.pay_status === '1'" size="normal">已发货</el-tag>
                     </template>
                 </el-table-column>
                 <el-table-column label="是否发货" >
                     <template slot-scope="scope">
                         <el-button type="primary" size="small" circle  plain v-if=" scope.row.is_send==='是'" icon='el-icon-check'></el-button>
                         <el-button type="warning" size="small" circle  plain v-if=" scope.row.is_send==='否'" icon='el-icon-close'></el-button>
                     </template>
                 </el-table-column>
                 <el-table-column label="下单时间"  width="250">
                     <template slot-scope="scope">
                         {{ scope.row.create_time | formateTime }}
                     </template>
                 </el-table-column>
                 <el-table-column label="操作" >
                     <template slot-scope="scope">
                         <el-tooltip  effect="dark" content="修改" placement="top">
                            <el-button 
                                type="success" 
                                size="small" 
                                @click="editUser(scope.row.id)" 
                                circle 
                                icon="el-icon-edit" 
                            ></el-button>
                        </el-tooltip>
                        <el-tooltip  effect="dark" content="查看物流信息" placement="top">
                            <el-button 
                                type="warning" 
                                size="small"  
                                @click="delUser(scope.row.id)"  
                                circle 
                                icon="el-icon-delete"
                            ></el-button>
                        </el-tooltip>
                     </template>
                 </el-table-column>
             </el-table>
             <!-- 分页器 -->
             <el-pagination
                 @current-change="currentChange"
                 :current-page.sync="searchForm.pagenum"
                 :page-size="searchForm.pagesize"
                 layout="total, prev, pager, next, jumper"
                 :total="total" background>
              >
             </el-pagination>

             <!-- 查看物流信息的弹框 -->
             <el-dialog
                 title=""
                 :visible.sync=""
                 width="30%"
                >
                 <span></span>
                 <span slot="footer">
                     <el-button @click=" = false">Cancel</el-button>
                     <el-button type="primary" @click="">OK</el-button>
                 </span>
             </el-dialog>
             
             
         </div>
    </el-card>
</template>

<script>
    let defaultItem = {
        user_id:'',
        pagesize:10,
        pagenum:1,
        pay_status:'',
        is_send:''
    }
    export default {
        data() {
            return {
                // 搜索表单的变量
                searchForm:{...defaultItem},
                total:0, // 总数
                orderList:[] // 订单列表
            }
        },
        created () {
            this.getOrderList()
        },
        methods: {
            async getOrderList() {
                // 发送请求
                let { data:res } = await this.$axios.get('orders',{
                    params:this.searchForm
                })
                // 错误处理
                if(res.meta.status !== 200) return this.$message.error(res.meta.msg)
                // 成功赋值
                this.orderList = res.data.goods
                this.total = res.data.total 
            },
            // 重置搜索框事件
            resetSearch(){
                this.searchForm = {...defaultItem}
                this.getOrderList()
            },
            // 页码更换事件
            currentChange(val){
                this.searchForm.pagenum = val
                this.getOrderList()
            }
        },
    }
</script>

<style lang="less" scoped>

</style>